﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Security;
using System.Security;
using System.Net.Sockets;
using System.Threading;
using System.ComponentModel;
namespace Common
{

    public class SendThread : MessageLooperBase
    {

        private SslStream dos;
        public SendThread(SslStream os)
        {
            this.dos = os;

        }

        protected override void handleItem(WorkItem anItem)
        {
            DataPackage package = anItem.data as DataPackage;
            if (!package.write(dos))
            {
                OnNetowrkFail();
            }

        }

        public void send(DataPackage mdcPackage)
        {
            WorkItem newItem = new WorkItem();
            newItem.data = mdcPackage;
            QueueItem(newItem);
        }
        public override void OnExited()
        {
            return;
        }
        public delegate void NetworkFailHandler();
        public event NetworkFailHandler OnNetowrkFail;
    }


}
